package com.itheima.service.umsService.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.db.ums.UmsRoleMenuRelation;
import com.itheima.mapper.umsMapper.UmsRoleMenuRelationMapper;
import com.itheima.service.umsService.UmsRoleMenuRelationService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author DogeGuo
 */
@DubboService
public class UmsRoleMenuRelationServiceImpl extends ServiceImpl<UmsRoleMenuRelationMapper, UmsRoleMenuRelation> implements UmsRoleMenuRelationService {
    @Autowired
    private UmsRoleMenuRelationMapper umsRoleMenuRelationMapper;

    //根据角色id集合,查询菜单id集合
    @Override
    public List<UmsRoleMenuRelation> findByRoleIds(List<Long> roleIds) {
        List<UmsRoleMenuRelation> roleMenuRelations = new ArrayList<>();

        //遍历角色id集合
        if (CollUtil.isNotEmpty(roleIds)) {
            roleIds.forEach(roleId ->{
                LambdaQueryWrapper<UmsRoleMenuRelation> lqw = new LambdaQueryWrapper<>();
                lqw.eq(UmsRoleMenuRelation::getRoleId,roleId);
                List<UmsRoleMenuRelation> menuRelations = umsRoleMenuRelationMapper.selectList(lqw);
                roleMenuRelations.addAll(menuRelations);
            });
        }
        return roleMenuRelations;
    }
}
